import { createRouter, createWebHistory } from 'vue-router'
import Home from '@/views/home'
import Login from '../views/login/index.vue'

const routes = [
  {
    path: '/',
    name: 'login',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: Login
  },
  {
    path: '/home',
    name: 'home',
    meta:{
      title:'首页'
    },
    component: Home,
    children:[
      {
        path: '/home',
        name: 'home',
        meta:{
          title:'首页'
        },
        component: () => import('@/views/home/home.vue'),
      },
      {
        path: '/modulemanagement',
        name: 'moduleManagement',
        redirect: '/classify',
        meta:{
          title:'模块管理'
        },
        component: () => import('@/views/routerView/parent.vue'),
        children:[
          {
            path: '/classify',
            name: 'classify',
            meta:{
              title:'分类管理'
            },
            component: () => import('@/views/moduleManagement/classify.vue'),
          },
          {
            path: '/commodity',
            name: 'commodity',
            meta:{
              title:'商品管理'
            },
            component: () => import('@/views/moduleManagement/commodity.vue'),
          },
          {
            path: '/add/:id',
            name: 'add',
            meta:{
              title:'添加商品'
            },
            component: () => import('@/views/moduleManagement/add.vue'),
          },
          {
            path: '/member',
            name: 'member',
            meta:{
              title:'会员管理'
            },
            component: () => import('@/views/moduleManagement/member.vue'),
          },
          {
            path: '/indent',
            name: 'indent',
            meta:{
              title:'订单管理'
            },
            component: () => import('@/views/moduleManagement/indent.vue'),
          },
        ]
      },
      {
        path: '/homeManagement',
        name: 'homeManagement',
        redirect: '/banner',
        meta:{
          title:'首页管理'
        },
        component: () => import('@/views/routerView/parent.vue'),
        children:[
          {
            path: '/banner',
            name: 'banner',
            meta:{
              title:'banner管理',
              icon:'Apple'
            },
            component: () => import('@/views/homeManagement/banner.vue'),
          },
          {
            path: '/statistics',
            name: 'statistics',
            meta:{
              title:'统计管理',
              icon:'Apple'
            },
            component: () => import('@/views/homeManagement/statistics.vue'),
          },
          {
            path: '/member',
            name: 'member',
            meta:{
              title:'会员管理',
              icon:'Apple'
            },
            component: () => import('@/views/moduleManagement/member.vue'),
          },
          {
            path: '/indent',
            name: 'indent',
            meta:{
              title:'订单管理',
              icon:'Apple'
            },
            component: () => import('@/views/moduleManagement/indent.vue'),
          },
        ]
      },
    ]
  },
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
router.beforeEach((to, _, next) => {
  document.title = to.meta.title
  next()
})

export default router
